<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>产品溯源</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <link rel="stylesheet" href="css/capacity.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	    <script type="text/javascript" src="js/companydata.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <section class="AllContent" style="background-color: #fff;">
	    	<div id="piclist">
	    		<!-- 溯源  -->
				<div id="ClothingTtyMain" style="margin-bottom:40px;border-bottom:2px solid #6CC83A;">
					
					<!-- 标题 -->
					<div class="ChothingTtyTitle" style="border-left:2px solid #6CC83A;">
						<i></i>
						<p>产品溯源过程</p>
					</div>
					
					<div style="overflow: hidden;" id="CentralBlock">
						<img style="width: 40%;margin:20px auto;display: block;" src="images/loading5.gif">
					</div>
				</div>
			</div>
	    	
	    	
	    	<section>
	    		<!-- 输入DIV -->
				<div class="theme-popover">
					
					<!-- 标题 -->
		        	<div class="InputNavigation">
		        		<p>公司溯源</p>
		        		<p class="exit"><img src="images/remove1.png"></p>
		        	</div>
		        	
		        	<!-- 商品信息   -->
		        	<div class="AddList">
		        		<div class="CommodityInfo">
		        			<div class="FormStyle">
		        				<ul style="width: 90%;">
			        				<li>网点：</li>
			        				<li>
										<select name="from_branch" id="from_branch">
	                                        <option value="0">选择网点</option>
	                                    </select>
			        				</li>
			        				<li>时间：</li>
			        				<li><input type="date" style="display: block;margin-top:4px;line-height:30px;" name="start_date" id="start_date" placeholder="格式：1000-00-00 00:00"/></li>
		        				
		        				</ul>
			        			
			        			<button class="NextButton" type="button" onclick="addtrack();">保存</button>
		        			</div>
		        		</div>
		        	</div>
				</div>
	    	</section>
				
			<!-- 遮罩层 -->
			<div class="theme-popover-mask"></div>
	    </section>
        
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript">
	    mui.init({
	    	
	    });
		$(function () {
			$('.AllHeader li:eq(1)').html("<a class='companyTy' href='CompanyTraceability.html'>公司</a><a class='productTy'>产品</a>");
			$('.AllHeader li:eq(2)').html('<img onclick="addtrackbox();" class="theme-login" style="width:22px" src="images/addproducts.png">');
			$('.titleTwo').css({lineHeight:'30px',marginTop:'5px'})
	        $('.ChothingTtyTitle').hide();
            $('.titleTwo a').css({color:'#fff',backgroundColor:'#00aafa'});
            $('.titleTwo a:eq(1)').css({color:'#0088CC',backgroundColor:'#fff'});
			
			$(".companyTy").on('tap',function(){
				mui.openWindow({
					url: 'CompanyTraceability.html', 
					id:'CompanyTraceability.html',
					show:{
				    	aniShow:'fade-in'//页面显示动画，默认为”slide-in-right“；
				    }
				});
			})
			
            /*遮罩*/
            $('.theme-login').click(function(){
				$('.theme-popover-mask').fadeIn(100);
				$('.theme-popover').slideDown(200);
				$('.AllContent').css({overflow:'hidden'});
			})
			$('.theme-popover-mask,.exit,.guanbi').click(function(){
				$('.theme-popover-mask').fadeOut(100);
				$('.theme-popover').slideUp(200);
				$('.AllContent').css({overflowY:'scroll'});
			})
			
			document.addEventListener('deviceready', onDeviceReady, true);
	        loadlotTrack();
		});
		
	    var tracklist = false;
	    function onDeviceReady() {
	        document.addEventListener("backbutton", onBackKeyDown, false);
	    }
	    function onBackKeyDown() {
	        openUrl("index.html");
	    }

        function addtrackbox(){
            $.ajax({
                type: "post",
                url: getServerUrl() + "/Open/Company/getbranchlist", //与此php页面沟通
                dataType: 'json', //从php返回的值以 JSON方式 解释
                data: 'access_token='+getToken(), //
                success: function (json) {//如果调用php成功
                    clist = json.branchlist;
                    var chtml = '';
                    if (!empty(clist)) {
                        for (var i = 0; i < clist.length; i++) {
                            if (!empty(clist[i])) {
                                chtml = chtml + '<option value="'+ clist[i].bid+'" src="'+ clist[i].branch_pic+'">' + clist[i].name + '</option>';
                            }
                        }
                    }
                    $("#from_branch").append(chtml);
                    $("#to_branch").append(chtml);
                    InitHeight()
                },
                error:function(json){
                    alertMessage(json.error_description);
                }
            });
        }
        function addtrack() {
            var pid = $_GET['pid'];
	        var from_branch = $("#from_branch").val();
	        var from_name = $("#from_branch").find("option:selected").text();
            var branch_pic = $("#from_branch").find("option:selected").attr("src");
	        var to_branch = $("#to_branch").val();
	        var to_name = $("#to_branch").find("option:selected").text();
	        var start_date = $("#start_date").val();
	        var end_date = $("#end_date").val();
	        if (empty(pid)) {
	            alertMessage("产品ID不能为空！");
	            return;
	        }
	        if (empty(from_branch) || from_branch == 0 ) {
	            alertMessage("请选择发货网点！");
	            return;
	        }
//	        if (empty(to_branch) || to_branch == 0 ) {
//	            alertMessage("请选择目的网点！");
//	            return;
//	        }
	        if (empty(start_date)) {
	            alertMessage("时间不能为空！");
	            return;
	        }
	        var datas = {access_token:getToken(),pid:pid,from_branch:from_branch,to_branch:to_branch,start_date:start_date,end_date:end_date,branch_pic:branch_pic};
            $.ajax({
                type: "post",
                url: getServerUrl() + "/Open/ComSys/addsource",
                dataType: 'json',
                data: datas,
                success: function (json) {
                    if (json.result == "1") {
                        var html = '';
                        html= html+ '<div class="ChotingTtyLeft">'
								+'<p>'+start_date.substring(0,4)+'</p>'
								+'<p>'+start_date.substring(5,10)+'</p>'
							+'</div>'
							
							+'<div class="ChotingTtyRight" style="border-left:2px solid #6CC83A;">'
								+'<i></i>'
								+'<p class="SKheightImg"><img width="100%" src="'+ branch_pic +'"></p>'
								+'<p class="BranchName2">'+ from_name +'</p>'
							+'</div>';
	                    
	                    $("#CentralBlock").prepend(html); 
	                    $('.theme-popover-mask').fadeOut(100);
	                    $('.theme-popover').slideUp(200);
	                    $('body').css({overflowY:'scroll'});
	                    $(".modal-body input").val("");
	                    hideTty();
                    } else {
                        alertMessage("添加溯源错误:[" + json.error_description + "]");
                    }
                }
            });
        }
        
        function removetrack(id) {
	        var r = confirm("请确认是否删除该溯源信息?")
	        if (r === true)
	        {
	            $.ajax({
	                type: "post",
	                url: getServerUrl() + "/Open/ComSys/deltrack",
	                dataType: 'json',
	                data:"access_token="+getToken()+ '&id=' + id,
	                success: function (json) {
	                    if (json.result == "1") {
	                        alertMessage("删除溯源信息完成！");
	                        loadlotTrack();
	                    } else {
	                        alertMessage("删除溯源信息错误:[" + json.error_description + "]");
	                    }
	                }
	            });
	        }
	
	    }
	</script>
</html>
